package com.superhelper.app.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.superhelper.app.common.Consts;
import com.superhelper.app.domain.Admin;
import com.superhelper.app.mapper.AdminMapper;
import com.superhelper.app.service.JHSmsHandler;

@Component("UserTask")
public class UserTask extends AbstractTask {

    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private JHSmsHandler smsService;

    /**
     * 用户是否过期
     */
    public void execute() {
        List<Admin> admins = adminMapper.getAdminTipsAt();
        for (final Admin a : admins) {
            long day = Consts.DAY_AGE;
            long time = System.currentTimeMillis() / 1000;
            long expireAt = a.getExpireAt().getTime() / 1000;
            long expireDay = (expireAt - time) / day;
            if (expireDay <= 3 && expireDay >= 0) {
                threadPool.execute(new Runnable() {
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        String tpl_id = "32440";
                        smsService.send(a.getUsername(), tpl_id, "");
                    }
                });
            }
        }
    }

}
